﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace CADprogram.Exception
{
    public class CreateLog
    {
        public static string logpath = ".\\log";
        public static void log(string text)
        {
            if (!Directory.Exists(logpath))
            {
                Directory.CreateDirectory(logpath);
            }
            string path = logpath + @"\\log" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.DayOfYear.ToString() + "_" + DateTime.Now.Hour.ToString() + ".txt";
            StreamWriter sw = new StreamWriter(path, true);
            sw.WriteLine(DateTime.Now.ToString() + "\n\r" + text);
            sw.Close();
        }
        public static void logException(System.Exception ex,string classname)
        {
            if (!Directory.Exists(logpath))
            {
                Directory.CreateDirectory(logpath);
            }
            string path = logpath + @"\\log" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.DayOfYear.ToString() + "_" + DateTime.Now.Hour.ToString() + ".txt";
            StreamWriter sw = new StreamWriter(path, true);
            sw.WriteLine(DateTime.Now.ToString() + "\n\r" + classname + "\n\r" + ex.Data.ToString() + "\n\r" + ex.Message + "\n\r" + ex.Source + "\n\r" + ex.StackTrace + "\n\r" + ex.TargetSite);
            sw.Close();
        }
    }
}
